PHP: parse $_FILES[] data in multidimesional array
Posted
by
superUntitled
on Stack Overflow
See other posts from Stack Overflow
or by superUntitled
Published on 2010-12-29T00:50:49Z
Indexed on
2010/12/29
0:53 UTC
Read the original article
Hit count: 187
php
|file-upload
I having been looking around for an answer to this and have not found an answer anywhere, I am hoping someone has done this before! I have a form that allows for dynamic duplication of the form fields. The form allows for file uploads and text input, so the data is sent in both $_POST and $_FILES arrays.
The the initial set of inputs look like this:
<input type="text" name="primary[1][text]" />
<input type="file" name="primary[1][file]" />
<input type="text" class="a" name="secondary[1][text][]" />
<input type="file" name="secondary[1][file][]" />
When duplicated the fields are incremented, they look like this:
<input type="text" name="primary[2][text]" />
<input type="file" name="primary[2][file]" />
<input type="text" class="a" name="secondary[2][text][]" />
<input type="file" name="secondary[2][file][]" />
To complicate matters, the "secondary" form fields can also be duplicated (thus the []
at the end of the secondary name array.
How can I parse the posted $_FILES array? I have tried something like this:
foreach ($_FILES['question'] as $f_num)
{
echo $f['file']['name'];
}
but I get an "Undefined index: file... " error.
© Stack Overflow or respective owner